# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=twisted-iocpsupport
_pyname=twisted_iocpsupport
pkgbase=mingw-w64-python-${_pyname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_pyname}
pkgver=1.0.2
pkgrel=2
pkgdesc='An extension for use in the twisted I/O Completion Ports reactor (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url='https://github.com/twisted/twisted-iocpsupport'
depends=(${MINGW_PACKAGE_PREFIX}-python)
makedepends=(${MINGW_PACKAGE_PREFIX}-cython
             ${MINGW_PACKAGE_PREFIX}-python-setuptools
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/twisted/${_realname}/archive/v${pkgver}.tar.gz
        001-fix-multiple-defs.patch)
sha256sums=('0b88af7bf592bbcf6b30ca685d3aef44daaabfa365b999f32fd1b0cb6df4901e'
            '615fe6e1ee621eafc69faefcada30258eb0692df44afac7020c29bf1555de958')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  cd "python-build-${MSYSTEM}"
  patch -p1 -i ${srcdir}/001-fix-multiple-defs.patch
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_pyname}/LICENSE"
}
